package org.linlinjava.litemall.db.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.linlinjava.litemall.db.dao.AdMapper;
import org.linlinjava.litemall.db.models.Ad;
import org.linlinjava.litemall.db.service.AdService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class AdServiceImpl extends ServiceImpl<AdMapper, Ad> implements AdService {

    @Override
    public List<Ad> queryIndex() {
        QueryWrapper<Ad> query = new QueryWrapper<>();
        query.eq("position", 1);
        query.eq("deleted", false);
        query.eq("enabled", true);
        return this.baseMapper.selectList(query);
    }

    @Override
    public IPage<Ad> querySelective(String name, String content, Integer pageNo, Integer pageSize) {
        Page<Ad> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Ad> query = new QueryWrapper<>();
        query.like(!StringUtils.isEmpty(name), "name", name);
        query.like(!StringUtils.isEmpty(content), "content", content);
        query.eq("deleted", false);
       return baseMapper.selectPage(page, query);
    }

}
